home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / rjs.lha / RJS / Transport / src / Transport.C < prev    next >
C/C++ Source or Header  |  1991-06-14  |  2KB  |  97 lines

  1. #include <libc.h>
  2. #include <osfcn.h>
  3. #include <sys/uio.h>
  4. #include <iostream.h>
  5. #include <errno.h>
  6.  
  7. #include "Transport.h"
  8. #include <RJS/Util.h>
  9.  
  10. RJS_Transport::RJS_Transport()
  11. {
  12.   td       = -1;
  13.   ss_set(SS_success);
  14.   return_on_error=0;
  15. }
  16.  
  17. int RJS_Transport::close()
  18. {
  19.   if (td == -1) { ss_set(SS_success); return 1; }
  20.   int s = ::close(td);
  21.   if (s==-1) {
  22.     ss_set(RJS_Status(errno));
  23.     if (return_on_error) return 0;
  24.     RJS_Util::crash_and_burn("RJS_Transport","close",ss_message());
  25.   }
  26.   else {
  27.     ss_set(SS_success);
  28.     td=-1;
  29.     return 1;
  30.   }
  31. }
  32.  
  33. int RJS_Transport::ok()
  34.     if (td==-1) return 0;
  35.     else return RJS_Status::ss_ok();
  36. }
  37.  
  38. int RJS_Transport::inuse()
  39.     return (td!=-1);
  40. }
  41.  
  42. int RJS_Transport::read(char *buffer, int mlen)
  43. {
  44.   if (td == -1) return -1;
  45.   int nbr = ::read(td,buffer,mlen);
  46.   if (nbr==-1) {
  47.     ss_set(RJS_Status(errno));
  48.     if (return_on_error) return nbr;
  49.     RJS_Util::crash_and_burn("RJS_Transport","read",ss_message());
  50.   }
  51.   else ss_set(SS_success);
  52.   return nbr;
  53. }
  54.  
  55. int RJS_Transport::readv(const struct iovec *iov, int iovlen)
  56. {
  57.   if (td == -1) return -1;
  58.   int nbr = ::readv(td,iov,iovlen);
  59.   if (nbr==-1) {
  60.     ss_set(RJS_Status(errno));
  61.     if (return_on_error) return nbr;
  62.     RJS_Util::crash_and_burn("RJS_Transport","readv",ss_message());
  63.   }
  64.   else ss_set(SS_success);
  65.   return nbr;
  66. }
  67.  
  68. int RJS_Transport::write(const char *buffer, int len)
  69. {
  70.   if (td == -1) return -1;
  71.   int nbw = ::write(td,buffer,len);
  72.   if (nbw==-1) {
  73.     ss_set(RJS_Status(errno));
  74.     if (return_on_error) return nbw;
  75.     RJS_Util::crash_and_burn("RJS_Transport","write",ss_message());
  76.   }
  77.   else ss_set(SS_success);
  78.   return nbw;
  79. }
  80.  
  81. int RJS_Transport::writev(const struct iovec *iov, int iovlen)
  82. {
  83.   if (td == -1) return -1;
  84.   int nbw = ::writev(td,iov,iovlen);
  85.   if (nbw==-1) {
  86.     ss_set(RJS_Status(errno));
  87.     if (return_on_error) return nbw;
  88.     RJS_Util::crash_and_burn("RJS_Transport","writev",ss_message());
  89.   }
  90.   else ss_set(SS_success);
  91.   return nbw;
  92. }
  93.  
  94.  
  95.